﻿using System;
using System.Net.Sockets;
using System.Text;

namespace DasherPacketSender
{

    /*
     This is a simple console app useful for testing packet formats and connectivity to Dasher.
     */

    class Program
    {
        private const string destination = "127.0.0.1";
        private const int dasherPort = 20320;
        private const string coordinate1Label = "x", coordinate2Label = "y";
        private static readonly UdpClient udpClient = new UdpClient(destination, dasherPort);

        static void Main()
        {
            while (true)
            {
                Console.WriteLine("Enter {0} value: ", coordinate1Label);
                string coordinate1Value = Console.ReadLine();
                Console.WriteLine("Enter {0} value: ", coordinate2Label);
                string coordinate2Value = Console.ReadLine();

                string packetContent = String.Format("{0} {1}\n{2} {3}\n",
                    coordinate1Label, coordinate1Value, coordinate2Label, coordinate2Value);

                Send(packetContent);
            }
        }

        private static void Send(string contents)
        {
            byte[] sendBuffer = Encoding.ASCII.GetBytes(contents);
            udpClient.Send(sendBuffer, sendBuffer.Length);
        }
    }
}
